package com.lsj.spring.aspect;

import com.lsj.spring.model.User;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;

/**
 * @author Lsj
 * @version 1.0
 * @date 2021/6/24 19:14
 */
public class LogAspectXml {

    public void insert(){}

    public void before(JoinPoint joinPoint){
        // 通过joinPoint可以拿到方法调用信息 getArgs获得传入目标方法的参数对象
        ((User)joinPoint.getArgs()[0]).setPassword("通过切面设置的");
        System.out.println("切面的前置操作");
    }

    public void after(){
        System.out.println("后置操作日志");
    }

    public Object aroundMethod(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("环绕中");
        Object res = pjp.proceed();
        System.out.println("环绕中");
        return res;
    }

    public void error(JoinPoint joinPoint){
        System.out.println("报错的处理方式");
    }
}
